export function closeTagsViewTag(temp, path) {
  const view = {
    path: path
  }
  temp.$store.dispatch('delVisitedViews', view).then((views) => {
    if (view.path === temp.$route.path) {
      const latestView = views.slice(-1)[0]
      if (latestView) {
        temp.$router.push(latestView.path)
      } else {
        temp.$router.push('/')
      }
    }
  })
}

export function closeCollectTag(temp) {
  const view = {
    path: '/reception/collect'
  }
  temp.$store.dispatch('delVisitedViews', view).then((views) => {
    if (view.path === temp.$route.path) {
      const latestView = views.slice(-1)[0]
      if (latestView) {
        temp.$router.push(latestView.path)
      } else {
        temp.$router.push('/')
      }
    }
  })
}

export function closeAuditTag(temp) {
  const view = {
    path: '/approval/accept-audit'
  }
  temp.$store.dispatch('delVisitedViews', view).then((views) => {
    if (view.path === temp.$route.path) {
      const latestView = views.slice(-1)[0]
      if (latestView) {
        temp.$router.push(latestView.path)
      } else {
        temp.$router.push('/')
      }
    }
  })
}

export function getAgeEtc(identityCard) {
  const info = {
    birthDay: null,
    age: null,
    sex: null
  }
  var len = (identityCard + '').length;
  if (len === 0) {
    return 0;
  } else {
    if ((len !== 15) && (len !== 18)) {
      return 0;
    }
  }
  var strBirthday = '';
  if (len === 18) {
    strBirthday = identityCard.substr(6, 4) + '/' + identityCard.substr(10, 2) + '/' + identityCard.substr(12, 2);
  }
  if (len === 15) {
    strBirthday = '19' + identityCard.substr(6, 2) + '/' + identityCard.substr(8, 2) + '/' + identityCard.substr(10, 2);
  }
  info.birthDay = strBirthday
  //时间字符串里，必须是“/”
  var birthDate = new Date(strBirthday);
  var nowDateTime = new Date();
  var age = nowDateTime.getFullYear() - birthDate.getFullYear();
  //再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
  if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() === birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
    age--;
  }
  info.age = age
  var gender = identityCard.slice(14, 17) % 2 ? '1' : '2'; // 1代表男性，2代表女性
  if (gender === '1'){
    info.sex = '男'
  } else {
    info.sex = '女'
  }
  return info
}
